﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="WaitingWarranty.aspx.cs" Inherits="MonkeyWarranty.Web.WarrantyTickets.WaitingWarranty" %>

<%@ Import Namespace="Resources" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>
        <%= GlobalStrings.WaitingWarranty %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row">
        <div class="col-lg-12">
            <h3><%=GlobalStrings.WaitingWarranty %></h3>
        </div>
    </div>
    
    <div class="row">
        <div class="col-lg-12">
            <div class="well">
                <div class="form-inline">
                    <input class="form-control" type="text" id="ticketcode" placeholder="<%=GlobalStrings.TicketCode %>" />
                    <input class="form-control" type="text" id="code" placeholder="<%=GlobalStrings.ProductCode %>" />
                    <input class="form-control" type="text" id="name" placeholder="<%=GlobalStrings.Name %> SP" />
                    <button class="btn btn-default" type="button" id="LoadRecordsButton"><i class="fa fa-search"></i></button>
                    <button class="btn btn-default" type="button" id="ResetButton"><i class="fa fa-refresh"></i></button>
                </div>
            </div>

            <div id="ProductsTableContainer"></div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <p></p>
            <p>
                
                <%--<input id="btnSendToTechnical" type="button" value="<%= GlobalStrings.SendToTechnical %>"
                    class="btn btn-success" data-toggle="modal" data-target="#myModal" />--%>
                <input id="btnSendToWarrantyDep" type="button" value="Chuyển phòng bảo hành"
                    class="btn btn-success" data-toggle="modal" data-target="#myModal2" />
            
                <%--<input id="btnSendToWarrantySupplier" type="button" value="<%= GlobalStrings.SendToWarrantySupplier %>"
                    class="btn btn-primary" data-toggle="modal" data-target="#myModal1" />--%>
            </p>
        </div>
    </div>
    
    <!-- SendToTechnical Modal -->
    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Chuyển phòng bảo hành</h4>
                </div>
                <div class="modal-body" id="confirmMessage">
                    <%=GlobalStrings.ProcessEmployee %><asp:DropDownList ID="ddlEmployees" runat="server" CssClass="form-control"></asp:DropDownList>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary" onclick="SendToWarrantyDep()" data-dismiss="modal">OK</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
    
    <%--<!-- SendToTechnical Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel"><%= GlobalStrings.SendToTechnical %></h4>
                </div>
                <div class="modal-body" id="confirmMessage">
                    <%=GlobalStrings.TechnicalEmployees %><asp:DropDownList ID="ddlEmployees" runat="server" CssClass="form-control"></asp:DropDownList>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary" onclick="SendToTechnical()" data-dismiss="modal">OK</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->--%>
    
    <%--<!-- SendToSupplier Modal -->
    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel1"><%= GlobalStrings.SendToWarrantySupplier %></h4>
                </div>
                <div class="modal-body" id="confirmMessage1">
                    <%=GlobalStrings.SendToWarrantySupplier %><asp:DropDownList ID="ddlSuppliers" runat="server" CssClass="form-control"></asp:DropDownList>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary" onclick="SendToWarrantySupplier()" data-dismiss="modal">OK</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->--%>


    <script type="text/javascript">
        $(function () {
            $("#menu-warranty").addClass("active");
            $("#menu1-warranty").addClass("collapse in");
            $("#menu1-waiting").addClass("active");
            LoadProducts();
        });
    </script>
    <script type="text/javascript">
        function LoadProducts() {
            $('#ProductsTableContainer').jtable({
                paging: true,
                pageSize: 15,
                sorting: true,
                defaultSorting: 'Name ASC',
                actions: {
                    listAction: 'WaitingWarranty.aspx/TicketProductList'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Select: {
                        title: '<input type="checkbox" id="chkAllProducts" onclick="javascript:ToggleAll();" />',
                        width: '1%',
                        sorting: false,
                        display: function (data) {
                            return '<input name="products" value="' + data.record.Id + '" type="checkbox" onclick="javascript:SelectProduct(' + data.record.Id + ');" />';
                        }
                    },
                    //WarrantyProductState: {
                    //    title: '<%= GlobalStrings.Status %>',
                    //    sorting: false
                    //},
                    TicketCode: { title: '<%= GlobalStrings.TicketCode %>', sorting: false },
                    ReceivedFromName: { title: '<%= GlobalStrings.ReceivedFrom %>', sorting: false },
                    DealerEmployeeName: { title: '<%= GlobalStrings.ReceivedFromName %>', width: '20%', sorting: false },
                    CustomerName: { title: '<%= GlobalStrings.Customers %>', sorting: false },
                    Phone: { title: '<%= GlobalStrings.Phone %>', sorting: false },
                    Code: {
                        title: '<%= GlobalStrings.ProductCode %>'
                    },
                    Name: {
                        title: '<%= GlobalStrings.ProductName %>'
                    },
                    Model: {
                        title: '<%= GlobalStrings.Model %>',
                        sorting: false
                    },
                    ManufacturerName: {
                        title: '<%= GlobalStrings.Manufacturers %>',
                        sorting: false
                    },
                    Serial: {
                        title: '<%= GlobalStrings.Serial %>',
                        sorting: false
                    },
                    Quantity: {
                        width: '5%',
                        title: '<%= GlobalStrings.Quantity %>',
                        sorting: false
                    },
                    WarrantyTypeName: {
                        title: '<%= GlobalStrings.WarrantyType %>',
                        sorting: false
                    }
                }
            });

            //Re-load records when user click 'load records' button.
            $('#LoadRecordsButton').click(function (e) {
                e.preventDefault();
                $('#ProductsTableContainer').jtable('load', {
                    name: $('#name').val(),
                    code: $('#code').val(),
                    ticketCode: $('#ticketcode').val()
                });
            });

            // Reset button
            $('#ResetButton').click(function (e) {
                e.preventDefault();
                $('#name').val('');
                $('#code').val('');
                $('#ticketcode').val('');
                $('#LoadRecordsButton').click();
            });

            //Load all records when page is first shown
            $('#LoadRecordsButton').click();
        }

        function SelectProduct(id) {
            var products = $('input[name=products]');
            for (var i = 0; i < products.length; i++) {
                if (products[i].checked == false) {
                    $('#chkAllProducts')[0].checked = false;
                    return;
                }
            }
            $('#chkAllProducts')[0].checked = true;
        }
    </script>

    <script type="text/javascript">
        var DdlEmployeesId = '#<%=ddlEmployees.ClientID %>';
        <%--var DdlSuppliersId = '#<%=ddlSuppliers.ClientID %>';--%>

        <%--function SendToTechnical() {
            var employeeId = $(DdlEmployeesId).val();
            if (employeeId == 0) {
                alert('<%=GlobalStrings.EmployeeIsRequired %>');
                return false;
            }

            var products = $('input[name=products]');
            var productIds = new Array();
            for (var i = 0; i < products.length; i++) {
                if (products[i].checked)
                    productIds.push(products[i].value);
            }

            if (productIds.length == 0) {
                alert("<%=GlobalStrings.SelectProduct %>");
                return false;
            }

            $.ajax({
                type: "POST",
                url: "WaitingWarranty.aspx/SendToTechnical",
                data: JSON.stringify({ productIds: productIds, employeeId: employeeId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    LoadProducts();
                },
                failure: function (errMsg) {
                    alert(errMsg);
                }
            });

            return false;
        }

        function SendToWarrantySupplier() {
            var supplierId = $(DdlSuppliersId).val();
            if (supplierId == 0) {
                alert('<%=GlobalStrings.SupplierRequired %>');
                return false;
            }

            var products = $('input[name=products]');
            var productIds = new Array();
            for (var i = 0; i < products.length; i++) {
                if (products[i].checked)
                    productIds.push(products[i].value);
            }

            if (productIds.length == 0) {
                alert("<%=GlobalStrings.SelectProduct %>");
                return false;
            }

            $.ajax({
                type: "POST",
                url: "WaitingWarranty.aspx/SendToWarrantySupplier",
                data: JSON.stringify({ productIds: productIds, supplierId: supplierId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    LoadProducts();
                },
                failure: function (errMsg) {
                    alert(errMsg);
                }
            });

            return false;
        }--%>

        function SendToWarrantyDep() {
            var employeeId = $(DdlEmployeesId).val();
            if (employeeId == 0) {
                alert('<%=GlobalStrings.EmployeeIsRequired %>');
                return false;
            }

            var products = $('input[name=products]');
            var productIds = new Array();
            for (var i = 0; i < products.length; i++) {
                if (products[i].checked)
                    productIds.push(products[i].value);
            }

            if (productIds.length == 0) {
                alert("<%=GlobalStrings.SelectProduct %>");
                return false;
            }

            $.ajax({
                type: "POST",
                url: "WaitingWarranty.aspx/SendToWarrantyDep",
                data: JSON.stringify({ productIds: productIds, employeeId: employeeId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    LoadProducts();
                },
                failure: function (errMsg) {
                    alert(errMsg);
                }
            });

            return false;
        }

        function ToggleAll() {
            var chkAll = $('#chkAllProducts')[0];
            var products = $('input[name=products]');
            for (var i = 0; i < products.length; i++) {
                products[i].checked = chkAll.checked;
            }
        }
    </script>
</asp:Content>
